home *** CD-ROM | disk | FTP | other *** search
/ CGI How-To / CGI HOW-TO.iso / chap6 / 6_8 / newd_c / formdata.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-06-15  |  1.1 KB  |  65 lines

  1.  
  2. #include <stdlib.h>
  3. #include <stdio.h>
  4. #include <string.h>
  5. #include "cgilib.h"
  6.  
  7. void main(int argc, char *argv[])
  8. {
  9.     /* Variables for the data. */
  10.     
  11.     Dictionary dataDict;
  12.     DictState iter;
  13.     
  14.     /* 
  15.      * Print the header required for all CGI scripts
  16.      * that output dynamic text data.
  17.      */
  18.     printf("Content-type: text/plain\n\n");
  19.     
  20.     /*
  21.      * Get the CGI data from the CGI library
  22.      */
  23.     
  24.     dataDict = readParse();
  25.     
  26.     printf("The form data is:\n\n");
  27.         
  28.     /* print the data */
  29.     
  30.     iter = dict_initState(dataDict);
  31.     
  32.     while(dict_nextState(&iter))
  33.     {
  34.         /* See if this is an array, if not, print it */
  35.         
  36.         if(strstr(iter.curNode->key,"A_") == iter.curNode->key)
  37.         {
  38.             Array theArray;
  39.             int i,max;
  40.             
  41.             theArray = (Array) iter.curNode->value;
  42.             
  43.             max = array_count(theArray);
  44.             
  45.             printf("Found a key with multiple values:\n");
  46.             
  47.             for(i=0;i<max;i++)
  48.             {
  49.                 /* Add 2 to the key to move past the A_ */
  50.                 printf("\t%s = %s\n",iter.curNode->key + 2,
  51.                                      array_itemAt(theArray,i));
  52.             }
  53.         }
  54.         else
  55.         {
  56.             printf("%s = %s\n",iter.curNode->key, iter.curNode->value);
  57.         }
  58.     }
  59.     
  60.     dict_free(dataDict);
  61.     
  62.     /* End the program */
  63.     exit(0);
  64. }
  65.